package com.cskaoyan.mall.order.controller.inner;

import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.order.dto.OrderInfoDTO;
import com.cskaoyan.mall.order.query.OrderInfoParam;
import com.cskaoyan.mall.order.service.OrderService;
import com.cskaoyan.mall.ware.api.dto.WareOrderTaskDTO;
import com.cskaoyan.mall.ware.api.dto.WareSkuDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Pudding
 * @Date 2024/7/17 15:06
 */
@RestController
public class OrderApiController {

    @Autowired
    OrderService orderService;

    //1. 通过订单id获取订单信息
    @GetMapping("/api/order/inner/getOrderInfo/{orderId}")
    public OrderInfoDTO getOrderInfoDTO(@PathVariable(value = "orderId") Long orderId){

        OrderInfoDTO orderInfo = orderService.getOrderInfo(orderId);
        return orderInfo;
    }


    //2. 支付成功，修改订单状态
    @PostMapping("/api/order/inner/success/{orderId}")
    public Result successPay(@PathVariable(value = "orderId") Long orderId){

        orderService.successPay(orderId);
        return Result.ok();
    }

    /**
     * 3. 拆单
     * @param orderId
     * @param wareSkuDTOList
     * @return
     */
    @PostMapping("/api/order/inner/orderSplit/{orderId}")
    List<WareOrderTaskDTO> orderSplit(@PathVariable(value = "orderId") String orderId, @RequestBody List<WareSkuDTO> wareSkuDTOList){

        List<WareOrderTaskDTO> wareOrderTaskDTOS = orderService.orderSplit(orderId, wareSkuDTOList);
        return wareOrderTaskDTOS;
    }

    /**
     * 4. 库存扣减完成，修改订单状态
     */
    @PostMapping("/api/order/inner/successLockStock/{orderId}/{taskStatus}")
    Result successLockStock(@PathVariable(value = "orderId") String orderId, @PathVariable(value = "taskStatus") String taskStatus){

        orderService.successLockStock(orderId, taskStatus);
        return Result.ok();
    }


    /**
     * 提交秒杀订单 ——> 现在我们使用消息消费，直接调用orderService.saveSeckillOrder(orderInfoParam);方法即可
     * @param orderInfoParam
     * @return
     */
    /*
    @PostMapping("/api/order/inner/seckill/submitOrder")
    Long submitOrder(@RequestBody OrderInfoParam orderInfoParam){
        return orderService.saveSeckillOrder(orderInfoParam);
    }
    */
}
